package edu.ccut.saturn.studio.logic.model.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnContent;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnTransformNode;

public class TranformNodeLoader extends NodeLoader {

	public List<Shape> loadNodes(Element root) {

		NodeList transformNodes = root
				.getElementsByTagName(SaturnTransformNode.KEY_NODE_TRANSFORM);

		List<Shape> shapes = new ArrayList<Shape>(transformNodes.getLength());

		for (int i = 0; i < transformNodes.getLength(); ++i) {
			SaturnTransformNode saturnTransformNode = new SaturnTransformNode();

			Node transformNode = transformNodes.item(i);
			String shapeId = super.getNodeAttributeValue(transformNode,
					Shape.KEY_NODE_TRANSFORM_ID);
			String nextId = super.getNodeAttributeValue(transformNode,
					Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID);

			String valueKey = super.getNodeElementValue(transformNode,
					SaturnTransformNode.KEY_TRANSFORM_NODE_VALUEKEY);
			String type = super.getNodeElementValue(transformNode,
					SaturnTransformNode.KEY_TRANSFORM_NODE_TYPE);
			
			String name = super.getNodeElementValue(transformNode,
					SaturnTransformNode.KEY_TRANSFORM_NODE_NAME);
			String description = super.getNodeElementValue(transformNode,
					SaturnTransformNode.KEY_TRANSFORM_NODE_DESCRIPTION);
			List<SaturnContent> contents = super.getContents((transformNode));

			Point location = super.getLocation(transformNode);
			Dimension size = new Dimension(50, 70);
			
			saturnTransformNode.setNode(transformNode);
			saturnTransformNode.setId(shapeId);
			saturnTransformNode.setLocation(location);
			saturnTransformNode.setName(name);
			saturnTransformNode.setNextId(nextId);
			saturnTransformNode.setDescription(description);
			saturnTransformNode.setContents(contents);
			saturnTransformNode.setSize(size);
			saturnTransformNode.setValueKey(valueKey);
			saturnTransformNode.setType(type);
			shapes.add(saturnTransformNode);
		}

		return shapes;
	}
}
